//
// GPSMapEdit
// (c) Konstantin Galichsky (kg@infratel.com), 2002-2004
//
// Object filter by type.
//

# include "StdAfx.h"
# include "Filter.h"
# include "TypeFilter.h"
# include "Map.h"
# include "MapView.h"
# include "Selection.h"
# include "Menu.h"

void CustomFilter (HWND _hWnd) {
	CTypeFilter tf;
	if (! tf.ShowSettings (_hWnd))
		return;

	//
	// Apply.
	//

	CCritSec::CLock lock (g_cs);

	for (size_t cKind = 0; cKind < rkMax; ++ cKind) {
		layer_t & layer = g_map.layers [cKind];
		rgns_t & rgns = layer.rgns;
		const size_t cRgns = layer.cRgns;

		for (rgns_t::iterator iRgn = rgns.begin (); iRgn != rgns.end (); ++ iRgn) {
			rgn_t & rgn = * iRgn;
			if (rgn.IsDeleted ())
				continue;

			if (tf.DoesFit (rgn)) {
				find_info_t fi;
				fi.pLayer = & layer;
				fi.iRgn = iRgn;
				fi.cElementOrOrigin = -1;
				g_Selection.push_back (fi);
			}
		}
	}

	Redraw ();
	UpdateMenu ();
}